﻿// Lavet af Andreas Horst, 3.semester.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DistributorWeb.VareService;

namespace DistributorWeb
{
    public partial class Default : System.Web.UI.Page
    {
        VareServiceClient vareServiceClient;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["service"] == null)
            {
                vareServiceClient = new VareServiceClient();
            }
            else
            {
                vareServiceClient = (VareServiceClient)Session["service"];
            }

            //dgvVarer.Visible = true;
            //dgvOrdre.Visible = true;
        }

        protected void btnHentForsendelser_Click(object sender, EventArgs e)
        {
            this.dgvVarer.DataSource = vareServiceClient.HentForsendelser();
            this.dgvVarer.DataBind();
        }

        protected void btnHentVare_Click(object sender, EventArgs e)
        {
            this.dgvVarer.DataSource = vareServiceClient.HentVarer();
            this.dgvVarer.DataBind(); // Kommer over i datagridview.
        }

        protected void btnHentOrdre_Click(object sender, EventArgs e)
        {
            this.dgvOrdre.DataSource = vareServiceClient.HentOrdreListe();
            this.dgvOrdre.DataBind(); // Kommer over i datagridview.
        }

        protected void btnOpskrivVare_Click(object sender, EventArgs e)
        {
            int varenr = int.Parse(txtbOpskrivVare.Text);
            double pris = double.Parse(txtbVareNrOp.Text);

            vareServiceClient.OpskrivVarensPris(varenr, pris);
        }

        protected void btnNedskrivVare_Click(object sender, EventArgs e)
        {
            int varenr = int.Parse(txtbNedskrivVare.Text);
            double pris = double.Parse(txtbVareNrNed.Text);

            vareServiceClient.NedskrivVarensPris(varenr, pris);
        }

        protected void btnLuk_Click(object sender, EventArgs e)
        {
            // Lukker browser-vindue ved hjælp af javascript.
            Response.Write("<script type='text/javascript'>window.opener='x';window.close();</script>");
        }



    }
}